package cn.edu.zzu.demo01Thread;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class DownloadThread implements Runnable{
    private String url ;
    private String fileName ;

    public DownloadThread(String url, String fileName) {
        this.url = url;
        this.fileName = fileName;
    }

    @Override
    public void run() {
        DownUtils.down(url , fileName);
        System.out.println(Thread.currentThread().getName()+"下载了"+fileName);
    }

    public static void main(String[] args) {

        new Thread(new DownloadThread("https://gitee.com/zhushangxue/blogimg/raw/master/img/20210804182542.png","1.png"),"下载1 ").start();
        new Thread(new DownloadThread("https://gitee.com/zhushangxue/blogimg/raw/master/img/20210804182542.png","2.png"),"下载2 ").start();
        new Thread(new DownloadThread("https://gitee.com/zhushangxue/blogimg/raw/master/img/20210804182542.png","3.png"),"下载3 ").start();
    }
}
class DownUtils{
    public static void down(String url , String fileName){
        try {
            FileUtils.copyURLToFile(new URL(url), new File(fileName));
        } catch (IOException e) {
           throw new RuntimeException("下载异常");
        }
    }
}
